Return * for n number of times


Posted by Christy on 2022-04-19

Description: Write a function that accepts a number n and returns * for n number of times

function star(n) {

}

console.log(star(3)); // ***
function star(n) {
  let result = "";
  for (let i = 1; i <= n; i++) {
    result += "*";
  }
  return result;
}

console.log(star(3));

Be careful about the way of ouput, if it's print -> console.log; if it's return -> return










Related Posts

Vue3 XML Pretty Print與Theme呈現

Vue3 XML Pretty Print與Theme呈現

[ 筆記 ]資訊安全 - 雜湊密碼:hash

[ 筆記 ]資訊安全 - 雜湊密碼:hash

F2E合作社|在HTML中設置錨點的三種方式

F2E合作社|在HTML中設置錨點的三種方式


Comments